﻿@using Webdiyer.WebControls.Mvc;
@using HiLand.General.Entity;
@using HiLand.Utility4.MVC;
@using GBFinance.Entity;
@using GBFinance.Web.Models;
@using HiLand.Utility4.MVC.Controls;
@model List<LoanScheduleEntity>
@{
    ViewBag.Title = "Secured Loan Schedule";
    Guid loanGuid = Guid.Empty;
    if (this.ViewData["LoanGuid"] != null)
    {
        loanGuid = new Guid(this.ViewData["LoanGuid"].ToString());
    }

    bool isDisplayGenerateButton = false;
    if (Model == null)
    {
        isDisplayGenerateButton = false;

    }
    else
    {
        if (Model.Count > 0)
        {
            isDisplayGenerateButton = false;
        }
        else
        {
            isDisplayGenerateButton = true;
        }
    }
}
<h2>
    Secured Loan List</h2>
<div class="OperateArea" id="OperateAreaContainer">

</div>
<div id="ItemListDIV">
    <table width="98%" class="grid">
        <tr>
            <th style="width: 80px">
                Operate
            </th>
            <th style="width: 30px">
                No.
            </th>
            <th style="width: 100px">
                Payment Amount
            </th>
            <th style="width: 100px">
                Payment Date
            </th>
            <th style="width: 100px">
                Paid Amount
            </th>
            <th style="width: 100px">
                Paid Date
            </th>
            <th>
                Memo
            </th>
        </tr>
        @for (int i = 0; i < Model.Count; i++)
        {
            LoanScheduleEntity entity = Model[i];
            int number = i + 1;
            string paidDateString = string.Empty;
            if (entity.PaidDate != HiLand.Utility.Data.DateTimeHelper.Min)
            {
                paidDateString = entity.PaidDate.ToString(Miscs.DateTimeFormating);
            }
            string paidAmount = string.Empty;
            if (entity.AmountPaid > 0)
            {
                paidAmount = entity.AmountPaid.ToString("0.00");
            }
                
            <tr>
                <td>
                    @Html.Link("Payment", @Url.Action("Payment", "SecuredLoan", new { scheduleGuid = entity.ScheduleGuid }), null)
                </td>
                <td>@number
                </td>
                <td>@entity.Amount.ToString()
                </td>
                <td>@entity.PaymentDate.ToString(Miscs.DateTimeFormating)
                </td>
                <td>
                    @paidAmount
                </td>
                <td>
                    @paidDateString
                </td>
                <td>
                </td>
            </tr>   
        }
    </table>
    <script type="text/javascript">
        $(document).ready(function () {
            var address = '@Url.Action("LoanInfoForSchedule")?loanGuid=@loanGuid' + '&isDisplayGenerateButton=@isDisplayGenerateButton';
            $("#OperateAreaContainer").load(address);
        });
</script>
</div>
